
clear 
close all;

width=1;
 
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        % INITIALIZE
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

data_directory= './';

tt_vec=[0.25 0.5 0.75]';
vrange_vec=[1.2 1.2 1.2]';        

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        % FIGURES 
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for tt=1:(size(tt_vec,1)),

        tau=tt_vec(tt,1);
        tau_text=num2str(100*tau);
        vrange=vrange_vec(tt,1);
        
        eval(['load ' data_directory '/' 'data_results_tau' num2str(100*tau) '.mat']);
               
        markertype=['kv-'; 'ko-'; 'k^-'];
        
        for yy_loop=1:size(x2_interest_univ,1),

                 yy_sel =x2_interest(yy_loop,1);

                                     
                 %==================================================================================================
                 figure; 
                         plot(x1_interest(x2_interest==yy_sel,1),CI_logQ_low_symmetrical_joint(2,x2_interest==yy_sel),'k-', ...
                                      x1_interest(x2_interest==yy_sel,1),CI_logQ_high_symmetrical_joint(2,x2_interest==yy_sel),'k-',...
                                      x1_interest(x2_interest==yy_sel,1),g_unconstr(x2_interest==yy_sel),markertype(yy_loop,:),'MarkerSize',3,'MarkerFaceColor','w')
                         hold on
                         title(['Symmetrical joint confidence intervals (' tau_text '-th quantile), ' x2_text(yy_loop,:)]);
                         plot(x1_interest(x2_interest==yy_sel,1),g_constr(x2_interest==yy_sel),markertype(yy_loop,:),'MarkerSize',3,'MarkerFaceColor','k')
                                      
                         grid on
                         v=axis;
                         vmean=mean(g_constr(x2_interest==yy_sel));
                         axis([v(1) v(2) vmean-vrange/2 vmean+vrange/2]);
                         xlabel('log price');
                         ylabel('log demand');
                         v=axis;
                         axis(v+[0 0 -0.06 -0.06]);
                         axis([0.20 0.365 6.5 7.9]);
                         legend('CI','CI','unconstrained exog','constrained exog');
         
                         name=['./g_income' num2str(exp(yy_sel)) '_tau' num2str(100*tau)];
                         savefig_fct(name,0);
                 %-------------------------------------------------------------------------------------------------
                 
         end;
         
         if (tau==0.5),

                        %%%%%%%%%%%%%%%%%%%%%%%%%
                        % MEAN CASE
                        %%%%%%%%%%%%%%%%%%%%%%%%%
                                        
                for yy_loop=1:size(x2_interest_univ,1),
        
                         yy_sel =x2_interest(yy_loop,1);
        
                                             
                         %==================================================================================================
                         figure; 
                                 plot(x1_interest(x2_interest_mean==yy_sel,1),CI_logQ_mean_low_symmetrical_joint(2,x2_interest_mean==yy_sel),'k-', ...
                                              x1_interest_mean(x2_interest_mean==yy_sel,1),CI_logQ_mean_high_symmetrical_joint(2,x2_interest==yy_sel),'k-',...
                                              x1_interest_mean(x2_interest_mean==yy_sel,1),g_mean_unconstr(x2_interest==yy_sel),markertype(yy_loop,:),'MarkerSize',3,'MarkerFaceColor','w')
                                 hold on
                                 title(['Symmetrical joint confidence intervals (mean case), ' x2_text(yy_loop,:)]);
                 
                                 plot(x1_interest_mean(x2_interest_mean==yy_sel,1),g_mean_constr(x2_interest==yy_sel),markertype(yy_loop,:),'MarkerSize',3,'MarkerFaceColor','k')
                                              
                                 grid on
                                 v=axis;
                                 vmean=mean(g_mean_constr(x2_interest_mean==yy_sel));
                                 axis([v(1) v(2) vmean-vrange/2 vmean+vrange/2]);
                                 xlabel('log price');
                                 ylabel('log demand');
                                 v=axis;
                                 axis(v+[0 0 -0.06 -0.06]);
                                 axis([0.20 0.365 6.5 7.9]);
                                 legend('CI','CI','unconstrained exog','constrained exog');
                 
                                 name=['./g_mean_income' num2str(exp(yy_sel))];
                                 savefig_fct(name,0);
                         %-------------------------------------------------------------------------------------------------
                         
                 end;

         end;
        
end;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % SELECT FIGURES
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%

copyfile('./g_income72500_tau50.pdf','./figure_1_a.pdf');
copyfile('./g_income57500_tau50.pdf','./figure_1_b.pdf');
copyfile('./g_income42500_tau50.pdf','./figure_1_c.pdf');

copyfile('./g_income57500_tau75.pdf','./figure_2_a.pdf');
copyfile('./g_income57500_tau50.pdf','./figure_2_b.pdf');
copyfile('./g_income57500_tau25.pdf','./figure_2_c.pdf');

copyfile('./g_mean_income72500.pdf','./figure_3_a.pdf');
copyfile('./g_mean_income57500.pdf','./figure_3_b.pdf');
copyfile('./g_mean_income42500.pdf','./figure_3_c.pdf');

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % PREPARE TABLE 5
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%

Prepare_table_5

    %
  
